package client;

import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Spatial;
import java.util.ArrayList;

/**
 *
 * @author Ben
 * Purpose: handles ingame items
//TASK: add crafting and proper inventory handling
 */
public class ObjectItem
{
    static final int maxItems = 256;
    static int[] itemID = new int[maxItems];
    static ArrayList<ItemData> itemData = new ArrayList();
    static LundWidget lund = new LundWidget();
    
    public ObjectItem()
    {
        
    }
    
    static public ItemData toID(int id, String na, String tex, String mod, boolean dyn)
    {
        return new ItemData(id,na,tex,mod,dyn);
    }
    
    public static void registerItem(int id, String na, String tex, String mod, boolean dyn)
    {
        if(itemData.size() < maxItems)
        {
            itemData.add(toID(id,na,tex,mod,dyn));
        }
        else
        {
            lund.printConsoleInfo("Max items reached.");
        }
    }
    
    static public class ItemBase extends ObjectItem
    {
        int inID;
        public ItemBase(int ID)
        {
            inID = ID;
        }
        
        public void spawn()
        {
            Spatial temp;
            temp = Main.appref.getAssetManager().loadModel(itemData.get(inID).modelpath);
            Material mat = new Material(Main.appref.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
            if(itemData.get(inID).texturepath.isEmpty())
            {
                mat.setBoolean("UseMaterialColors", true);
                mat.setColor("Diffuse", ColorRGBA.Magenta);
                mat.setColor("Specular", ColorRGBA.White);
                mat.setFloat("Shininess", 12);
            }
            else
            {
                mat.setTexture("DiffuseMap", lund.loadTexture(itemData.get(inID).texturepath));
                mat.setColor("Specular", ColorRGBA.White);
                mat.setFloat("Shininess", 12);
            }
            temp.setMaterial(mat);
            temp.setName(itemData.get(inID).name);
            temp.setLocalTranslation(Main.player.getLocation());
            FloatingText tempt = new FloatingText(temp.getName(),temp,0,0);
            Main.rendernode.attachChild(temp);
        }
    }
}
